package com.sbl.bajw.util;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;

public class HttpUtil {

	public static String getData(String url,NameValuePair[] pars,String chartSet) {
		
		HttpClient httpClient=new HttpClient();
		PostMethod postMethod=new PostMethod(url); //设置路径
		postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, chartSet); //设置编码
		if(pars != null){
			postMethod.setRequestBody(pars);   //设置传递参数
		}
		
		String result=null;
		try {
		   httpClient.executeMethod(postMethod);
		   
		   result=postMethod.getResponseBodyAsString();
		} catch (HttpException e) {
			System.out.println(e.getMessage());
			e.printStackTrace();
		} catch (IOException e) {
			System.out.println(e.getMessage());
			e.printStackTrace();
		}                 
		postMethod.releaseConnection();              //释放连接
		return result;
	}
}
